package com.kafeblog.roo.portletmvc.utils;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.process.manager.FileManager;
import org.springframework.roo.project.Path;
import org.springframework.roo.project.PathResolver;

@Component
@Service
public class ValidateHelperImpl implements ValidateHelper {
	@Reference private FileManager fileManager;
	@Reference private PathResolver pathResolver;
	
	@Override
	public boolean filesMustNotExists(Path context, String... files) {
		boolean ok = true;
		for (String file: files) {
			if (fileManager.exists(pathResolver.getFocusedIdentifier(context, file))) {
				ok = false;
				break;
			}
		}
		return ok;
	}
	
	@Override
	public boolean filesMustExists(Path context, String... files) {
		boolean ok = true;
		for (String file: files) {
			if (!fileManager.exists(pathResolver.getFocusedIdentifier(context, file))) {
				ok = false;
				break;
			}
		}
		return ok;
	}
}
